<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <section>
        <form action="">
            <!-- 姓名、密码、邮箱、电话 -->
            <label for="userName">姓名:</label><input type="text" name="userName" id="userName"><br>
            <label for="password">密码:</label><input type="text" name="password" id="password"><br>
            <label for="email">邮箱:</label><input type="text" name="email" id="email"><br>
            <label for="tel">电话:</label><input type="text" name="tel" id="tel"><br>
            <label for="qq">qq号:</label><input type="text" name="qq" id="qq"><br>

            <input type="submit">
        </form>
    </section>
    <section>
        <span class="remind">提示信息</span>
    </section>


    <script>
        // 名字 ：中文 且 2-4个字符 [\u4e00-\u9fa5]
        // 手机号 ： 1开头 第二位是3456789 且 11位
        // 邮箱： 数字字母下划线构成 @数字字母(2-多个).2-4字母.2-4字母（可有可无）
        //     fdaf12_fds@qq.com.cn
        // qq号 ：开头1-9 中间 0-9 最少5位 最多11位
        // 密码强度：
        //     1.密码不低于8位
        //     2.如果是纯数字或者纯字母 密码强度低
        //     3.包含数字字母 密码强度中
        //     4.包含数字字母下划线且有大写字母 密码强度高
        var flag = false;
        var userName = document.querySelector("#userName");
        var password = document.querySelector("#password");
        var email = document.querySelector("#email");
        var tel = document.querySelector("#tel");
        var qq = document.querySelector("#qq");
        var remind = document.querySelector(".remind");
        userName.onblur = function () {
            var reg = /^[\u4e00-\u9fa5]{2,4}$/;
            var str = this.value;
            if (reg.test(str)) {
                remind.innerHTML = "姓名符合规范";
                remind.style.color = "green";
                flag = true;
            } else {
                remind.innerHTML = "姓名不符合规范";
                remind.style.color = "red";
                flag = false;
            }
        }
        password.onblur = function () {
            var reg = /[\w\W]{8,}/;
            var str = this.value;
            // console.log(reg,str,reg.test(str));
            if (reg.test(str)) {
                // console.log((/[a-z]/g).test(str)&&(/\d/g).test(str)&&(/[A-Z]/g).test(str)&&(/_/g).test(str));
                switch (true) {
                    case (/[a-z]/g).test(str) && (/\d/g).test(str) && (/[A-Z]/g).test(str) && (/_/g).test(str):
                        remind.innerHTML = "密码强度高";
                        remind.style.color = "green";
                        break;
                    case (/[a-zA-Z]/g).test(str) && (/\d/g).test(str):
                        remind.innerHTML = "密码强度中";
                        remind.style.color = "yellow";
                        break;
                    case (/^\d+$|^[a-zA-Z]+$/g).test(str):
                        remind.innerHTML = "密码强度低";
                        remind.style.color = "black";
                        break;
                    default: remind.innerHTML = "11111";
                        break;
                }
                flag = true;
            } else {
                remind.innerHTML = "密码不符合规范";
                remind.style.color = "red";
                flag = false;
            }
        }
        email.onblur = function () {
            var reg = /^\w+@([a-zA-Z0-9]{2,})(\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,4})?)$/;
            var str = this.value;
            if (reg.test(str)) {
                remind.innerHTML = "邮箱符合规范";
                remind.style.color = "green";
                flag = true;
            } else {
                remind.innerHTML = "邮箱不符合规范";
                remind.style.color = "red";
                flag = false;
            }
        }
        tel.onblur = function () {
            var reg = /^1[3-9]\d{9}$/;
            var str = this.value;
            if (reg.test(str)) {
                remind.innerHTML = "电话符合规范";
                remind.style.color = "green";
                flag = true;
            } else {
                remind.innerHTML = "电话不符合规范";
                remind.style.color = "red";
                flag = false;
            }
        }
        qq.onblur = function () {
            var reg = /^[1-9][0-9]{4,10}$/;
            var str = this.value;
            if (reg.test(str)) {
                remind.innerHTML = "qq号符合规范";
                remind.style.color = "green";
                flag = true;
            } else {
                remind.innerHTML = "qq号不符合规范";
                remind.style.color = "red";
                flag = false;
            }
        }
    </script>
</body>

</html>